package com.zryc.shop.pms.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zryc.shop.pms.entity.Brand;
import com.zryc.shop.pms.entity.Product;
import com.zryc.shop.pms.mapper.BrandMapper;
import com.zryc.shop.pms.service.IBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zryc.shop.ums.entity.Admin;
import com.zryc.shop.ums.entity.Menu;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 品牌表 服务实现类
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements IBrandService {

    /**
     * 分页查询品牌列表
     *
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Page<Brand> list(String keyword, Integer pageNum, Integer pageSize) {
        Page<Brand> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Brand> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(keyword)) {
            wrapper.like("name", keyword).or()
                    .like("first_letter",keyword).or()
                    .eq("id",keyword).or()
                    .eq("sort",keyword);
        }
        return page(page, wrapper);
    }

    /**
     * 更新是否为品牌制造商
     * @param ids
     * @param factoryStatus
     * @return
     */
    @Override
    public Object updateFactoryStatus(Long ids, Integer factoryStatus) {
        UpdateWrapper<Brand> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", ids);
        updateWrapper.set("factory_status", factoryStatus);
        update(updateWrapper);
        return null;
    }

    /**
     * 更新(可以全部)显示状态
     *
     * @param ids
     * @param showStatus
     * @return
     */
    @Override
    public Object updateShowStatus(String ids, Integer showStatus) {
        String[] idList=ids.split(",");
        UpdateWrapper<Brand> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", idList);
        updateWrapper.set("show_status", showStatus);
        update(updateWrapper);
        return null;
    }

    /**
     * 修改品牌
     *
     * @param id
     * @param brand
     * @return
     */
    @Override
    public Object updateBrand(Long id, Brand brand) {
        UpdateWrapper<Brand> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        baseMapper.update(brand,updateWrapper);
        return null;
    }
}
